
// 根据ID转化为名称
const idToName=(list,id)=>{
  for(var i=0; i<list.length; i++){
    if(list[i].id==id){
      return list[i].name
    }
  }
}

  // 判断该页面是否已过期
const check_pageInvalid=(invalid_time)=>{
  // console.log('判断该页面是否已过期',new Date(invalid_time))
    if(new Date() > new Date(invalid_time)){
      wx.showModal({
        content: '该链接已过期，请联系您的老师，重发链接',
        showCancel: false,
        title: '提示',
        success: res => {
          wx.switchTab({
            url: '/pages/index_theory/index_theory',
          })
        },
      })
    }
  }

// 提交前数据检查
const check_submitData=(submit_data)=>{
  // 检查用户ID是否存在
  if(isNaN(submit_data.user_id)){
    wx.showModal({
      showCancel: false,
      title: '未检测到用户ID，请联系客服',
    })
    return
  }else if(!submit_data.real_name){   // 检查是否实名认证
    wx.showModal({
      showCancel: false,
      title: '请认证姓名',
    })
    return
  }else if(!submit_data.id_no){   // 检查是否实名认证
    wx.showModal({
      showCancel: false,
      title: '请认证身份证号',
    })
    return
  }else if(!submit_data.phone){   // 检查是否授权手机
    wx.showModal({
      showCancel: false,
      title: '请授权手机号',
    })
    return
  }else if(!submit_data.license_id){ // 检查用户是否设置执照类型
    wx.showModal({
      showCancel: false,
      title: '请设置执照种类',
    })
    return
  }else if(!submit_data.type_id){ // 检查用户是否设置类别等级
    wx.showModal({
      showCancel: false,
      title: '请设置类别等级',
    })
    return
  }else if(!submit_data.rank_id){ // 检查用户是否设置类别等级
    wx.showModal({
      showCancel: false,
      title: '请设置操控员等级',
    })
    return
  }else if(!submit_data.nation){
    wx.showModal({
      showCancel: false,
      title: '请选择民族',
    })
    return
  }else if(!submit_data.province){
    wx.showModal({
      showCancel: false,
      title: '请填写地址',
    })
    return
  }else if(!submit_data.address){
    wx.showModal({
      showCancel: false,
      title: '请填写详细地址',
    })
    return
  }else if(!submit_data.email){
    wx.showModal({
      showCancel: false,
      title: '请填写邮箱地址',
    })
    return
  }
  return true
}

// 提交的数据打包
const package_data=(that)=>{
  let stu_info = that.data.stu_info
  let user_info = that.data.user_info
  let page_data = that.data.page_data
  return {user_id:that.user_id, jg_id:that.jg_id, ...stu_info, ...user_info, ...page_data,}
}

module.exports={
  idToName:idToName,
  check_submitData:check_submitData,
  package_data:package_data,
  check_pageInvalid:check_pageInvalid
}